home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / TARFILE.GZ / tarfile / ch_3.5 / bcd / edge / thld.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  686 b   |  36 lines

  1. /*
  2.  * (c) Copyright 1988 by
  3.  * Robotics Principles Research Department, ATT Bell Laboratories.
  4.  * All rights reserved.
  5.  * Last modified 2/8/88 Ingemar J. Cox
  6.  * C version 8/2/88 Deborah A. Wallach
  7.  * Automatic thresholding 9/30/88 Ingemar J. Cox
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "edge_finder.h"
  12.  
  13. extern struct image *my_image;
  14.  
  15. int image_threshold()
  16. {
  17.     int ix, iy, nx, ny;
  18.     int *detx, tmp;
  19.     float mad = 0; /* calculate mean absolute deviation */
  20.  
  21.     detx=my_image->idx;
  22.     nx = my_image->nx;
  23.     ny = my_image->ny;
  24.  
  25.     for(iy=0;iy<ny;iy++)
  26.     {
  27.         for(ix=0;ix<nx;ix++)
  28.         {
  29.             tmp = *detx++;
  30.             mad += abs(tmp);
  31.         }
  32.     }
  33.     return((int)((float)(3*mad/nx/ny)/0.8));
  34. }
  35.  
  36.